 #!/usr/bin/env python3
"""
检查API服务器的当前工作目录
"""

import requests
import json

def check_api_server():
    """检查API服务器状态"""
    print("🔍 检查API服务器状态...")
    
    try:
        # 测试一个简单的端点
        url = "http://127.0.0.1:8000/api/v1/prediction/model-status"
        response = requests.get(url, timeout=10)
        
        if response.status_code == 200:
            data = response.json()
            print("✅ API服务器正在运行")
            
            # 分析模型状态
            model_status = data.get('model_status', {})
            print(f"\n📊 模型状态分析:")
            
            for model_name, status in model_status.items():
                is_trained = status.get('is_trained', False)
                file_exists = status.get('file_exists', False)
                print(f"  🤖 {model_name}: 已训练={is_trained}, 文件存在={file_exists}")
                
                if is_trained and not file_exists:
                    print(f"    ⚠️  问题: 显示已训练但文件不存在")
                elif not is_trained and file_exists:
                    print(f"    ⚠️  问题: 文件存在但显示未训练")
                elif not is_trained and not file_exists:
                    print(f"    ✅ 正常: 未训练且文件不存在")
                else:
                    print(f"    ✅ 正常: 已训练且文件存在")
            
            # 尝试获取更详细的错误信息
            print(f"\n🧪 测试单日预测API...")
            test_url = "http://127.0.0.1:8000/api/v1/prediction/single-day-prediction"
            test_params = {
                "target_date": "2025-07-20",
                "model": "xgboost"
            }
            
            test_response = requests.get(test_url, params=test_params, timeout=30)
            print(f"📊 测试响应状态码: {test_response.status_code}")
            print(f"📄 测试响应内容: {test_response.text}")
            
        else:
            print(f"❌ API服务器响应异常: {response.status_code}")
            print(f"📄 响应内容: {response.text}")
            
    except requests.exceptions.ConnectionError:
        print("❌ 无法连接到API服务器，请确保服务器正在运行")
    except Exception as e:
        print(f"❌ 检查失败: {e}")

if __name__ == "__main__":
    check_api_server()